package ServletTest;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Scanner;
import java.util.logging.Filter;

/*
模拟Servlet本质
 */
public class WebServer {
    public static void main(String[] args){
        FileInputStream fis = null;
        try {
            Scanner scanner = new Scanner(System.in);
            String url = scanner.nextLine();
            fis = new FileInputStream("src/webFile.properties");
            Properties properties = new Properties();
            properties.load(fis);
            String className = properties.getProperty(url);
            //创建Servlet对象，调用service方法
            Class c = Class.forName(className);
            MyServlet myServlet = (MyServlet) c.newInstance();
            myServlet.service();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
